#!/usr/bin/perl

use CGI;
$query = CGI::new();
print $query->header();

$v = $query->param("v");

$id = $v;
$id =~ /v=(.*)&/;
if (!defined($1)) {
   $id =~ /v=(.*)/;
   $id = $1;
} else {
   $id = $1;
}

$f = "webm/$id.webm";

if (! -e $f) {
    # 43 = webm
    # 18 = mp4
    $z = `./youtube-dl -o $f -f 43 --quiet $v`;
}

print "$f\n";
